package DailyQuestion;

public class finalString {
    public static void main(String[] args) {
        String s = "poiinter";
        System.out.println(new finalString().finalString(s));
    }
    public String finalString(String s) {
        String result = "";
        for (int i = 0; i < s.length(); i++) {
            if(s.charAt(i) == 'i'){
                result = reverse(result);
            }
            else {
                result += s.charAt(i);
            }
        }
        return result;
    }
    public String reverse(String result){
        char[] re_ = result.toCharArray();
        int left = 0,right = result.length() - 1;
        while (right > left){
            char temp = re_[right];
            re_[right] = re_[left];
            re_[left] = temp;
            right--;
            left++;
        }
        return new String(re_);
    }
}
